package com.example.demo.msg.nio;/**
 * Created by kete on 2018-08-10.
 */

import java.util.Scanner;

/**
 * 作者：kete
 * 创建时间：2018-08-10 17:27
 * 功能描述：
 * 版本：
 */
public class SocketClient {

    private static ClientHandle clientHandle;

    public static void start(){
        if(clientHandle!=null)
            clientHandle.stop();

        clientHandle = new ClientHandle();

        new Thread(clientHandle,"Client").start();
    }

    public static boolean sendMsg(String msg) throws Exception{
        if("q".equals(msg)) return false;

        clientHandle.send(msg);

        return true;
    }

    public static void main(String[] args) {

        SocketClient.start();

        try {
            while (SocketClient.sendMsg(new Scanner(System.in).nextLine()));

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
